package com.ruoyi.web.controller.base;

import com.ruoyi.base.domain.BaseBelongOfficeContact;
import com.ruoyi.base.service.IBaseBelongOfficeContactService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * 属地应急联络;Controller
 * 
 * @author ruoyi
 * @date 2024-07-22
 */
@Api(description="属地应急联络表管理")
@RestController
@RequestMapping("/base/belongOfficeContact")
public class BaseBelongOfficeContactController extends BaseController
{
    @Autowired
    private IBaseBelongOfficeContactService baseBelongOfficeContactService;

    /**
     * 查询属地应急联络;列表
     */
    @ApiOperation("查询属地应急联络")
    @GetMapping("/list")
    public TableDataInfo list(BaseBelongOfficeContact baseBelongOfficeContact)
    {
        startPage();
        List<BaseBelongOfficeContact> list = baseBelongOfficeContactService.selectBaseBelongOfficeContactList(baseBelongOfficeContact);
        return getDataTable(list);
    }

    /**
     * 导出属地应急联络;列表
     */
    @ApiOperation("导出属地应急联络")
    @Log(title = "属地应急联络;", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseBelongOfficeContact baseBelongOfficeContact)
    {
        List<BaseBelongOfficeContact> list = baseBelongOfficeContactService.selectBaseBelongOfficeContactList(baseBelongOfficeContact);
        ExcelUtil<BaseBelongOfficeContact> util = new ExcelUtil<BaseBelongOfficeContact>(BaseBelongOfficeContact.class);
        util.exportExcel(response, list, "属地应急联络;数据");
    }

    /**
     * 获取属地应急联络;详细信息
     */
    @ApiOperation("获取属地应急联络")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") String ID)
    {
        return success(baseBelongOfficeContactService.selectBaseBelongOfficeContactByID(ID));
    }

    /**
     * 新增属地应急联络;
     */
    @ApiOperation("新增属地应急联络")
    @Log(title = "属地应急联络;", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseBelongOfficeContact baseBelongOfficeContact)
    {
        baseBelongOfficeContact.setID(UUID.randomUUID().toString().replace("-", ""));
        baseBelongOfficeContact.setCreatedBy(getUserId().toString());
        baseBelongOfficeContact.setCreatedTime(new Date());
        return toAjax(baseBelongOfficeContactService.insertBaseBelongOfficeContact(baseBelongOfficeContact));
    }

    /**
     * 修改属地应急联络;
     */
    @ApiOperation("修改属地应急联络")
    @Log(title = "属地应急联络;", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseBelongOfficeContact baseBelongOfficeContact)
    {
        baseBelongOfficeContact.setUpdatedBy(getUserId().toString());
        baseBelongOfficeContact.setUpdatedTime(new Date());
        return toAjax(baseBelongOfficeContactService.updateBaseBelongOfficeContact(baseBelongOfficeContact));
    }

    /**
     * 删除属地应急联络;
     */
    @ApiOperation("删除属地应急联络")
    @Log(title = "属地应急联络;", businessType = BusinessType.DELETE)
	@DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable String[] IDs)
    {
        return toAjax(baseBelongOfficeContactService.deleteBaseBelongOfficeContactByIDs(IDs));
    }
}
